F<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="项目" prop="grantId">
        <el-select v-model="queryParams.grantId" placeholder="请选择项目" @change="queryGrantSelectChange">
          <el-option
            v-for="dict in grantOptions"
            :key="dict.grantId"
            :label="dict.grantName"
            :value="dict.grantId"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="考点" prop="examPointId">
        <el-select v-model="queryParams.examPointId" placeholder="请选择考点" clearable>
          <el-option
            v-for="dict in pointOptions"
            :key="dict.id"
            :label="dict.epName"
            :value="dict.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="grantId">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="证件号码" prop="grantId">
        <el-input
          v-model="queryParams.idcard"
          placeholder="请输入证件号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否导入" prop="isImport">
        <el-select v-model="queryParams.isImport" placeholder="请选择是否导入" clearable size="small">
          <el-option
            v-for="dict in yesnoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否确认" prop="isConfirm">
        <el-select v-model="queryParams.isConfirm" placeholder="请选择是否确认" clearable size="small">
          <el-option
            v-for="dict in yesnoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="需要替班" prop="isNeedReplace">
        <el-select v-model="queryParams.isNeedReplace" placeholder="请选择是否需要替班" clearable size="small">
          <el-option
            v-for="dict in yesnoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否替班" prop="isReplace">
        <el-select v-model="queryParams.isReplace" placeholder="请选择是否替班" clearable size="small">
          <el-option
            v-for="dict in yesnoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="考官单位" prop="companyName">
        <el-input v-model="queryParams.companyName" placeholder="请输入考官所属单位" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['grant:examinergrant:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['grant:examinergrant:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['grant:examinergrant:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['grant:examinergrant:export']"
        >导出</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          @click="handleImport"
        >导入人员</el-button>
        <el-col :span="1.5">
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handleTeacherExport"
            v-hasPermi="['grant:examinergrant:export']"
          >教师资格导出</el-button>
        </el-col>
        <el-col :span="1.5">
          <el-button
            type="warning"
            icon="el-icon-download"
            size="mini"
            @click="handlePointExport"
            v-hasPermi="['grant:examinergrant:export']"
          >考点导出</el-button>
        </el-col>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="examinergrantList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="项目" align="center" prop="grantId" :formatter="grantFormat" width ="200px"/>
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="证件号码" align="center" prop="idcard"  width ="200px"/>
      <el-table-column label="性别" align="center" prop="sex" :formatter="sexFormat"/>
      <el-table-column label="民族" align="center" prop="nation" />
      <el-table-column label="科类大类" align="center" prop="type" :formatter="typeFormat"/>
      <el-table-column label="科类小类" align="center" prop="subjectCode" :formatter="subjectCodeFormat" />
      <el-table-column label="参加过" align="center" prop="isJoin" :formatter="joinFormat" />
      <el-table-column label="考点" align="center" prop="examPointId" :formatter="pointFormat" width ="200px"/>
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="银行卡号" align="center" prop="blankCark" width ="200px" />
      <el-table-column label="银行名称" align="center" prop="blankName"  width ="200px"/>
      <el-table-column label="银行电话" align="center" prop="blankPhone" />
      <el-table-column label="银行电话" align="center" prop="unitId" />
      <el-table-column label="派出单位" align="center" prop="companyId" :formatter="companyFormat"  width ="200px"/>
      <el-table-column label="考官单位" align="center" prop="companyName" width ="200px" />
      <el-table-column label="开户行" align="center" prop="depositName"  width ="200px"/>
      <el-table-column label="是否组长" align="center" prop="isMasterExaminer" :formatter="masterFormat"/>
      <el-table-column label="是否导入" align="center" prop="isImport" :formatter="importFormat"/>
      <el-table-column label="是否确认" align="center" prop="isConfirm" :formatter="confirmFormat"/>
      <el-table-column label="出行类型" align="center" prop="joinType" />
      <el-table-column label="考官工作单位" align="center" prop="jobComname" />
      <el-table-column label="需要替班" align="center" prop="isNeedReplace" />
      <el-table-column label="是否替班" align="center" prop="isReplace" />
      <el-table-column label="关联人ID" align="center" prop="relationGrexaminerId" />
      <el-table-column label="关联人姓名" align="center" prop="relationGrexaminerName" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['grant:examinergrant:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['grant:examinergrant:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="getQrcode(scope.row)"
            v-hasPermi="['grant:examiner:replace']"
          >替班</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改报名信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="性别">
              <el-select v-model="form.sex" placeholder="请选择性别" clearable size="small">
                <el-option
                  v-for="dict in sexOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="证件号码" prop="idcard">
              <el-input v-model="form.idcard" placeholder="请输入证件号码" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="职称">
              <el-select v-model="form.technicalTitle" placeholder="请选择职称">
                <el-option
                  v-for="dict in titleOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
              <el-form-item label="项目" prop="grantId">
                <el-select v-model="form.grantId" placeholder="请选择项目" @change="grantSelectChange">
                  <el-option
                    v-for="dict in grantOptions"
                    :key="dict.grantId"
                    :label="dict.grantName"
                    :value="dict.grantId"
                  />
                </el-select>
              </el-form-item>
          </el-col>
          <el-col :span="12">
              <el-form-item label="科类大类">
                <el-select v-model="form.type" placeholder="请选择科类大类" @change="typeChange">
                  <el-option
                    v-for="dict in typeOptions"
                    :key="dict.id"
                    :label="dict.familiesName"
                    :value="dict.id"
                  />
                </el-select>
              </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="科类小类" prop="subjectCode">
              <el-select v-model="form.subjectCode" placeholder="请选择科类小类" @change="subjectChange">
                <el-option
                  v-for="dict in subjectOptions"
                  :key="dict.id"
                  :label="dict.familiesName"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="考点" prop="examPointId">
              <el-select v-model="form.examPointId" placeholder="请选择考点" >
                <el-option
                  v-for="dict in examPointSelectOptions"
                  :key="dict.id"
                  :label="dict.epName"
                  :value="dict.id"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="银行卡号" prop="blankCark">
              <el-input v-model="form.blankCark" placeholder="请输入银行卡号" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="银行名称" prop="blankName">
              <el-input v-model="form.blankName" placeholder="请输入银行名称" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="银行电话" prop="blankPhone">
              <el-input v-model="form.blankPhone" placeholder="请输入银行电话" />
            </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="银行电话" prop="unitId">-->
<!--              <el-input v-model="form.unitId" placeholder="请输入银行电话" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
<!--        </el-row>-->
<!--        <el-row>-->
          <el-col :span="12">
              <el-form-item label="派出单位" prop="companyId">
                <treeselect v-model="form.companyId" :options="grcompanyOptions" :normalizer="normalizer" placeholder="请选择派出单位" />
              </el-form-item>
          </el-col>
<!--          <el-col :span="12">-->
<!--            <el-form-item label="考官所属单位" prop="companyName">-->
<!--              <el-input v-model="form.companyName" placeholder="请输入考官所属单位" />-->
<!--            </el-form-item>-->
<!--          </el-col>-->
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="开户行" prop="depositName">
              <el-input v-model="form.depositName" placeholder="请输入开户行" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否组长" prop="isMasterExaminer">
              <el-select v-model="form.isMasterExaminer" placeholder="请选择是否组长" >
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否导入" prop="isImport">
              <el-select v-model="form.isImport" placeholder="请选择是否导入" >
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否确认" prop="isConfirm">
              <el-select v-model="form.isConfirm" placeholder="请选择是否确认" >
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="是否参加过" prop="isJoin">
              <el-select v-model="form.isJoin" placeholder="请选择是否参加过" >
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" placeholder="请输入备注" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="需要替班" prop="isJoin">
              <el-select v-model="form.isNeedReplace" placeholder="请选择是否需要替班" :disabled='isAdmin'>
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联用户ID" prop="remark">
              <el-input v-model="form.relationGrexaminerId" placeholder="关联用户ID" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="是否替班" prop="isJoin">
              <el-select v-model="form.isReplace" placeholder="请选择是否替班" :disabled='isAdmin'>
                <el-option
                  v-for="dict in yesnoOptions"
                  :key="dict.dictValue"
                  :label="dict.dictLabel"
                  :value="dict.dictValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联用户姓名" prop="remark">
              <el-input v-model="form.relationGrexaminerName" placeholder="关联用户姓名" />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 人员导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
        <treeselect v-model="upload.companyId" :options="grcompanyOptions" :normalizer="normalizer" placeholder="请选择派出单位" />
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?grantId=' + queryParams.grantId+'&companyId='+upload.companyId"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">
          将文件拖到此处，或
          <em>点击上传</em>
        </div>
        <div class="el-upload__tip" slot="tip">
          <el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
        </div>
        <div class="el-upload__tip" style="color:red" slot="tip">提示：仅允许导入“xls”或“xlsx”格式文件！</div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 生成二维码对话框 -->
    <el-dialog :title="qrtitle" :visible.sync="qropen" width="500px" append-to-body>
      <div align="center">
        <span style="font-size: 18px">{{grantName}}</span>
        <span style="font-size: 18px">{{companyName}}</span>
        <div id="qrCode" ref="qrCodeUrl">
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listExaminergrant,
  getExaminergrant,
  delExaminergrant,
  addExaminergrant,
  updateExaminergrant,
  exportExaminergrant,
  downTemplate,
  exportTeacherExaminergrant,exportPointExaminergrant
} from "@/api/grant/examinergrant";
import {listGrantAll} from "@/api/grant/grant";
import { getFamiliesFormatList } from "@/api/grant/grantfamilies";
import { getExamPointlist,getExamponitListByFamiliesId,listExampoint } from "@/api/grant/exampoint"
import {listGrcompany, getCompanyList, getUserCompanyPanelData} from "@/api/grant/grcompany"
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {getToken} from "@/utils/auth";
import ExportJsonExcel from "js-export-excel";
import QRCode from "qrcodejs2";
export default {
  name: "Examinergrant",
  components: { Treeselect },
  data() {
    return {
      isAdmin: false,
      qrtitle: '考官替班二维码(仅限本人使用)',
      qropen: false,
      grantName: undefined,
      companyName: undefined,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 报名信息表格数据
      examinergrantList: [],
      grantOptions: [],
      yesnoOptions:[],
      sexOptions:[],
      familiesOptions:[],
      exampointOptions:[],//列表翻译用
      examPointSelectOptions:[],//表单页面选择用
      pointOptions:[],//查询选择用
      companyOptions:[],
      grcompanyOptions:[],
      titleOptions: [],
      typeOptions:[],
      subjectOptions:[],
      enrollHost: undefined, //报名的域名，从后台系统配置表获取
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        examinerId: undefined,
        grantId: undefined,
        examinerCode: undefined,
        type: undefined,
        subjectCode: undefined,
        isJoin: undefined,
        examPointId: undefined,
        blankCark: undefined,
        blankName: undefined,
        blankPhone: undefined,
        unitId: undefined,
        companyId: undefined,
        companyName: undefined,
        depositName: undefined,
        isMasterExaminer: undefined,
        isImport: undefined,
        isConfirm: undefined,
        joinType: undefined,
        compayUserId: undefined,
        name: undefined,
        idcard: undefined,
        isNeedReplace: undefined,
        isReplace: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 人员导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        companyId: undefined,
        open: false,
        // 弹出层标题（用户导入）
        title: "人员导入",
        // 是否禁用上传
        isUploading: false,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/grant/examinergrant/importData"
      }
    };
  },
  created() {
    this.getDicts("technical_title").then(response => {
      this.titleOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.yesnoOptions = response.data;
    });
    this.getDicts("sys_user_sex").then(response => {
      this.sexOptions = response.data;
    });
    getFamiliesFormatList().then(response => {
      this.familiesOptions = response.data;
    });
    getExamPointlist().then(res=>{
      this.exampointOptions = res.data;
    });
    let comquery={}
    getCompanyList(comquery).then(res=>{
      this.companyOptions = res.data;
    })
    let query ={};
    query["isEnabled"]="0";
    listGrantAll(query).then(res=>{
      this.grantOptions = res.data;
      this.queryParams.grantId=res.data[res.data.length-1].grantId;
      //查询项目对应考点
      let pointQueryParams = {
        pageNum: 1,
        pageSize: 100,
        epCode: undefined,
        epName: undefined,
        departId: undefined,
        granttypeId: res.data[res.data.length-1].granttypeId,
        isEnabled: undefined,
        createUser: undefined,
        epExplain: undefined,
        isBank: undefined,
        isIssuingBank: undefined,
        bankNameLimit: undefined,
        bankTypeLimit: undefined
      };

      listExampoint(pointQueryParams).then(response => {
        this.pointOptions = response.rows;

      });


      this.getList();
      this.getTreeselect();
      this.getUserCompanyPanelData();
    })
  },
  methods: {
    getUserCompanyPanelData(){
      let query = {};
      query['grantId'] = this.queryParams.grantId;
      getUserCompanyPanelData(query).then(res =>{
        //查一下替班二维码的域名。
        // this.companyList = res.data.companyList;
        // this.plannedQuantity = res.data.plannedQuantity;
        // this.enrollQuantity = res.data.enrollQuantity;
        // this.companyName = res.data.companyName;
        this.companyLvl = res.data.lvl;
        // this.companyId  = res.data.companyId;
        // this.formCompanyId = res.data.formCompanyId;
        this.enrollHost = res.data.enrollHost;
        if(this.companyLvl==2 || this.companyLvl==3){
          this.isAdmin=true;
        }
      })
    },
    /** 查询报名信息列表 */
    getList() {
      this.loading = true;
      listExaminergrant(this.queryParams).then(response => {
        this.examinergrantList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 转换派出单位管理数据结构 */
    normalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.id,
        label: node.comName,
        children: node.children
      };
    },
    /** 查询派出单位下拉树结构 */
    getTreeselect() {
      let comQueryParam = {};
      comQueryParam["grantId"] = this.queryParams.grantId;
      listGrcompany(comQueryParam).then(response => {
        this.grcompanyOptions = [];
        const data = { id: 0, comName: '顶级节点', children: [] };
        data.children = this.handleTree(response.data, "id", "parentId");
        this.grcompanyOptions.push(data);
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        examinerId: undefined,
        grantId: undefined,
        examinerCode: undefined,
        type: undefined,
        subjectCode: undefined,
        isJoin: undefined,
        examPointId: undefined,
        remark: undefined,
        blankCark: undefined,
        blankName: undefined,
        blankPhone: undefined,
        unitId: undefined,
        companyId: undefined,
        companyName: undefined,
        depositName: undefined,
        isMasterExaminer: 'N',
        isImport: 'N',
        isConfirm: 'N',
        joinType: undefined,
        compayUserId: undefined,
        name: undefined,
        idcard: undefined,
        post: undefined,
        addr: undefined,
        technicalTitle: undefined,
        phone: undefined,
        photoUrl: undefined,
        photoStatus: undefined,
        sex: undefined,
        isNeedReplace:'N',
        isReplace: 'N'
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.form.grantId=this.queryParams.grantId;
      this.grantSelectChange(this.form.grantId);
      this.title = "添加报名信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getExaminergrant(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改报名信息";
        this.grantSelectChange(this.form.grantId);
        this.subjectChange(this.form.subjectCode);
        this.typeChange(this.form.type);
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      var actions = [];
      Object.keys(this.companyOptions).map((key) => {
        if(this.companyOptions[key].id==this.form.companyId){
          actions.push(this.companyOptions[key].comName);
        }
      })
      this.form.companyName = actions.join('');
      console.log(this.form.companyName)
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateExaminergrant(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              }
            });
          } else {
            addExaminergrant(this.form).then(response => {
              if (response.code === 200) {
                this.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              }
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除报名信息编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delExaminergrant(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报名信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportExaminergrant(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    },
    /** 教师资格导出按钮操作 */
    handleTeacherExport(){
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报名信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportTeacherExaminergrant(queryParams);
      }).then(response => {
        this.download(response.msg);
      }).catch(function() {});
    },
    /** 考点导出按钮操作 */
    handlePointExport(){
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有报名信息数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return exportPointExaminergrant(queryParams);
      }).then(response => {
        this.download(response.msg);
      }).catch(function() {});
    },
    grantFormat(row,column){
      var actions = [];
      Object.keys(this.grantOptions).map((key) => {
        if(this.grantOptions[key].grantId==row.grantId){
          actions.push(this.grantOptions[key].grantName);
        }
      })
      return actions.join('');
    },
    sexFormat(row,column){
      return this.selectDictLabel(this.sexOptions, row.sex);
    },
    importFormat(row,colum){
      return this.selectDictLabel(this.yesnoOptions, row.isImport);
    },
    confirmFormat(row,colum){
      return this.selectDictLabel(this.yesnoOptions, row.isConfirm);
    },
    masterFormat(row,column){
      return this.selectDictLabel(this.yesnoOptions, row.isMasterExaminer);
    },
    joinFormat(row,column){
      return this.selectDictLabel(this.yesnoOptions, row.isJoin);
    },
    typeFormat(row,column){
      var actions = [];
      Object.keys(this.familiesOptions).map((key) => {
        if(this.familiesOptions[key].id==row.type){
          actions.push(this.familiesOptions[key].familiesName);
        }
      })
      return actions.join('');
    },
    subjectCodeFormat(row,column){
      var actions = [];
      Object.keys(this.familiesOptions).map((key) => {
        if(this.familiesOptions[key].id==row.subjectCode){
          actions.push(this.familiesOptions[key].familiesName);
        }
      })
      return actions.join('');
    },
    pointFormat(row,column){
      var actions = [];
      Object.keys(this.exampointOptions).map((key) => {
        if(this.exampointOptions[key].id==row.examPointId){
          actions.push(this.exampointOptions[key].epName);
        }
      })
      return actions.join('');
    },
    companyFormat(row,column){
      var actions = [];
      Object.keys(this.companyOptions).map((key) => {
        if(this.companyOptions[key].id==row.companyId){
          actions.push(this.companyOptions[key].comName);
        }
      })
      return actions.join('');
    },
    queryGrantSelectChange(value)
    {
      this.typeOptions=[];
      this.subjectOptions=[];
      Object.keys(this.grantOptions).map((key)=>{
        if(this.grantOptions[key].grantId==value){
          this.getTypeOptions(this.grantOptions[key].granttypeId);
          //查询项目对应考点
          let pointQueryParams = {
            pageNum: 1,
            pageSize: 100,
            epCode: undefined,
            epName: undefined,
            departId: undefined,
            granttypeId: this.grantOptions[key].granttypeId,
            isEnabled: undefined,
            createUser: undefined,
            epExplain: undefined,
            isBank: undefined,
            isIssuingBank: undefined,
            bankNameLimit: undefined,
            bankTypeLimit: undefined
          };

	        listExampoint(pointQueryParams).then(response => {
            this.pointOptions = response.rows;

          });
          return;
        }
      })
      this.queryParams.grantId = value;
      this.getTreeselect();


    },
    grantSelectChange(value){
      this.typeOptions=[];
      this.subjectOptions=[];
      Object.keys(this.grantOptions).map((key)=>{
        if(this.grantOptions[key].grantId==value){
          this.getTypeOptions(this.grantOptions[key].granttypeId);
          return;
        }
      })
      this.queryParams.grantId = value;
      this.getTreeselect();
    },getTypeOptions(granttypeId){
      Object.keys(this.familiesOptions).map((key)=>{
        if(this.familiesOptions[key].parentId===0 && this.familiesOptions[key].granttypeId===granttypeId){
          this.typeOptions.push(this.familiesOptions[key]);
        }
      })
    },typeChange(value){
      this.subjectOptions=[];
      this.getSubjectOptions(value);
    },getSubjectOptions(parentId){
      Object.keys(this.familiesOptions).map(key=>{
        if(this.familiesOptions[key].parentId===parentId){
          this.subjectOptions.push(this.familiesOptions[key]);
        }
      })
    },subjectChange(value){
      getExamponitListByFamiliesId({'grantId':this.form.grantId,'familiesId':value}).then(res=>{
        console.log(res);
        this.examPointSelectOptions = res.data;
        console.log(this.examPointSelectOptions);
      })
    },
    /** 导入 按钮操作 */
    handleImport() {
      this.upload.title = "人员导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      return downTemplate().then(res=>{
        this.download(res.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      console.log('response',response)
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg, "导入结果", { dangerouslyUseHTMLString: true });
      //导出失败的记录
      if(response.data!=null)
      {
        this.exportExcel(response.data)
      }
      this.getList();
    },
    exportExcel(list) {

      const dataList = list;

      let option = {};  //   option代表的就是excel文件

      let dataTable = [];   //   dataTable代表excel文件中的数据内容
      if (dataList) {
        for (let i in dataList) {
          let obj = {
            考官姓名: dataList[i].name,
            身份证号码: dataList[i].idcard,
            导入失败原因: dataList[i].failerReason
          };

          dataTable.push(obj);   //   设置excel每列获取的数据源
        }
      }

      option.filename = "导入失败的人员";  //excel文件名
      //excel文件数据
      option.datas = [
        {
          //   excel文件的数据源
          sheetData: dataTable,
          //   excel文件sheet的表名
          sheetName: "模板",
          //   excel文件表头名
          sheetHeader: ["考官姓名", "身份证号码","导入失败原因"],
          //   excel文件列名
          sheetFilter: ["考官姓名", "身份证号码","导入失败原因"],
        },
      ];
      //   创建ExportJsonExcel实例对象
      let toExcel = new ExportJsonExcel(option);
      //   调用保存方法
      toExcel.saveExcel();
    },
    // 提交上传文件
    submitFileForm() {

      if(this.queryParams.grantId==undefined)
      {
        this.$alert('导入数据请选择项目', "提示", { dangerouslyUseHTMLString: true });
        return;
      }
      this.$refs.upload.submit();
    },
    //生成替换二维码
    getQrcode(row){
      this.grantName = this.grantFormat(row,1);
      this.companyName = this.companyFormat(row,1);
      this.qropen = true;
      if(this.qrFlag) {
        this.delQrcode();
      }
      this.qrFlag = true;
      let enrollUrl=this.enrollHost;
      setTimeout(function() {
        enrollUrl+="/#/loginPage?grantId="+row.grantId+"&companyId="+row.companyId+"&rpIdCard="+row.idcard;
        console.log(enrollUrl);
        let a = new QRCode('qrCode', {
          text: enrollUrl, // 需要转换为二维码的内容
          width: 200,
          height: 200,
          colorDark: "black", //#000000为黑色
          colorLight: "white",
        });
      },200);

    }// 清空二维码,避免生成多个二维码
    ,delQrcode(){
      this.$refs.qrCodeUrl.innerHTML = ""
    },
  }
};
</script>
